package org.biojava.services.das.servlets;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

import org.biojava.services.das.dao.DasServer;
import org.biojava.utils.xml.PrettyXMLWriter;
import org.biojava.utils.xml.XMLWriter;

public class DasServerWriterImpl implements DasServerWriter{

	public void writeDasServer(XMLWriter xw, DasServer server)
			throws IOException {
		xw.openTag("SERVER");
		// System.out.println("DasSourceWriterImpl:  writing new source");

		xw.attribute("uri", server.getUrl());
		String description=server.getDescription();
		if(description!=null){
		xw.attribute("description", description);
		}
		int userId = server.getUserId();
		String sourceControlled="no";
		
		if(userId!=0)sourceControlled="yes";
		xw.attribute("server_controlled",sourceControlled);
		xw.attribute("number_of_sources", Integer.toString(server.getNumberOfSources()));
		xw.closeTag("SERVER");
		
	}

	public void writeDasSource(OutputStream stream, DasServer server)
			throws IOException {
		
		PrintWriter pw = new PrintWriter(stream);
		PrettyXMLWriter xw = new PrettyXMLWriter(pw);
		writeDasServer(xw, server);
		
	}

}
